package cn.itcast.mq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SpringRabbitListener {

    @RabbitListener(queues = "ad.queue2")
    public void listenSimpleQueue(String msg) {
        log.debug("消费者接收到simple.queue的消息：【" + msg + "】");
        System.out.println(1 / 0);
        log.info("消费者处理消息成功！");
    }

    // 声明接收延迟消息的交换机和队列


    // 声明接收死信队列的消息
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "art415.dl.queue", durable = "true"),
            exchange = @Exchange(name = "art415.dl.direct"),
            key = "art415.dl"
    ))
    public void listenDlQueue(String msg) {
        log.info("消费者接收到了文章延迟发布的消息，现在就发文章:"+msg);
    }

//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "art.delay.queue", durable = "true"),
//            exchange = @Exchange(name = "art.delay.direct", delayed = "true"),
//            key = "art.delay"
//    ))
//    public void listenDelayExchange(String msg) {
//        log.info("消费者接收到了art.delay.queue的延迟消息，消息到了，可以发文章了");
//    }
}
